package com.titan.core.utils.dbinfo.bean;

import com.titan.core.utils.data.FormatUtils;

/**
 * @author 周成功
 * @email 86898837@qq.com
 * @date 2020年02月14日
 */
public class TableBean {
    private String nameEn;    
    private String nameZh;
    private String comments;
    private String type;
    private String[] primaryKey;
    private String[][] uniqueIndex;
    private ColumnBean[] columns;

    public ColumnBean getColumn(String name) {
        for (ColumnBean bean : columns) {
            if(bean.getNameEn().equalsIgnoreCase(name)) {
                return bean;
            }
        }
        return null;
    }
    
    
    public String toString() {
        StringBuffer info =new StringBuffer(1024);
        info.append("nameEn="+nameEn+",");
        info.append("nameZh="+nameZh+",");
        info.append("comments="+comments+",");
        info.append("type="+type+"\n");
        info.append("uniqueIndex="+FormatUtils.toString(uniqueIndex)+"\n");
        parseArray("primaryKey", info, primaryKey);
        parseArray("columns", info, columns);
        return info.toString();
    }
    private void parseArray(String name, StringBuffer info, Object[] index) {
        if(index==null) return;
        info.append(name+"=[");
        for (int i = 0; i < index.length; i++) {
            if(i>0) {
                info.append(",");
            }
            info.append(index[i]);
        }
        info.append("]\n");
    }


    public TableBean() {
    }
    
    public String getNameEn() {
        return nameEn;
    }
    
    public void setNameEn(String nameEn) {
        this.nameEn = nameEn;
    }
    
    public String getNameZh() {
        return nameZh;
    }
    
    public void setNameZh(String nameZh) {
        this.nameZh = nameZh;
    }
    
    public String getComments() {
        return comments;
    }
    
    public void setComments(String comments) {
        this.comments = comments;
    }
    
    public String getType() {
        return type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
    public String[] getPrimaryKey() {
        return primaryKey;
    }
    
    public void setPrimaryKey(String[] primaryKey) {
        this.primaryKey = primaryKey;
    }
    
    public ColumnBean[] getColumns() {
        return columns;
    }
    
    public void setColumns(ColumnBean[] columns) {
        this.columns = columns;
    }


    public String[][] getUniqueIndex() {
        return uniqueIndex;
    }

    public void setUniqueIndex(String[][] uniqueIndex) {
        this.uniqueIndex = uniqueIndex;
    }
    
    
}
